package com.colin.videoservice.listener;

import cn.dev33.satoken.stp.StpUtil;
import com.colin.videoservice.mapper.VideoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DelayVideoListener {
    @Autowired
    private VideoMapper videoMapper;

    @RabbitListener(queues = "delay.video.dlq")
    public void delayCloseDraft(Long videoId) {
        String loginId = (String) StpUtil.getLoginId();
        if (videoMapper.checkPublish(loginId, videoId) != null) {
            return ;
        }
        log.info("未发布视频即将关闭 视频id：{}", videoId);
        videoMapper.deleteVideoDraft(videoId);
    }
}
